関将史
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    C#用 === クラスのコピー --- そういうわけで何かそーすがあればここならリンクも貼り放題ですし ソースコードもコピペし放題ですよ request.GetType().GetProperties(). 上記で.を打ってもForEachがでてこない。 reversalResponse.GetType().GetProperties().ToList().ForEach(p => Console.WriteLine(p.Name)); すみません、ToListがいるかもしれないです これでコピーできる? さっきと書き方微妙に違いますが。 *は何かな_? ? > 強調表示したかっただけですね > request.GetType().GetProperties().ToList().ForEach(p => p.SetValue(tempRequest, p.GetValue(request))); でOK? requestからtempRequestへコピーするならそうですね 動く・・・・・・はずです typeof(TRequest).GetProperty("プロパティ名 "); もしもし はいはい クラスのメンバ取得 --- GetProperty("プロパティ名"); でプロパティが入れ子になっている場合取れないかな? 入れ子とはクラス化されている typeof(TRequest).GetProperty("class1.field") みたいな感じで 潜るのが一番の近道かと思います typeof(TRequest).GetProperty("class1").GetType().GetProperty("field") ですかね 一つ目のtypeof(TRequest)はTRequestの型を取得しているだけなので、内部全てまで再帰的に全て解析してマッピングしてくれてるわけじゃないですね /// <summary> /// JSONオブジェクトの値を文字列として取得する /// </summary> /// <param name="obj"></param> /// <returns></returns> private static string GetValueText(object obj) { string result = string.Empty; else if (type == typeof(string)) { result = obj.ToString(); } else if (type.IsClass) { // この辺 result = $"{{{GenerateKeyValueText(obj)}}}"; } else { result = obj.ToString(); } return result; } なるほど ……ただ、ここまでして取らなきゃいけない場合は試験用ならともかく、本番用のソースだとするとまず普通にアクセスできるようにクラスの型変えたほうがいいのではないですかね・・・ 確かに・・・ 元があまりいけてない こんな感じで、外部から拾いやすいとこにパスを通すとか これだとReadonlyなので外から弄られませんし public class sample{ public Class1 class1; public string field => class1.field;// ←追加 } public class Class1{ public string field; } 内部のソースで見に行ってるってことはビルドした時点で見に行くのが分かり切っているのだから そのように実装すべき、 でないとクラスのメンバ名をVisualStudioで一括で変えたとき、GetPropertyの中の文字列まで変ってくれないですよ Shift+F12での参照箇所検索でも引っかかりませんし 動かしたら参照エラーで例外が出ますが。。。 ありがとうございます、またお願いします。 もしもし(7月8日) レスポンスでContent-Encodingを設定する方法を教えて下さい レスポンス…… var request = new HttpRequestMessage(method, url); request.Content = new StringContent(jsonRequest, Encoding.UTF8, "application/json"); の、Encoding.UTF8のとこですね request.Content.Headers.ContentType.CharSet = "UTF-8"; auPayで無理やり設定したときはこれ使いましたね 圧縮するようなこと書いてあります。 Encodingと圧縮は関係ないような気がしますが・・・ Encoding.UTF8はキャラクターのエンコードでは? そうですけれど それ以外に何を?画像データのバイナリでも送るのですか? https://sqlazure.jp/r/%E6%9C%AA%E5%88%86%E9%A1%9E/559/ 今のプロジェクトってこの圧縮を使うんです? 相手がこの圧縮に対応してる必要があるように見えますが レスポンスで圧縮して返したいらしいです・・・ http://myamamo0417.blogspot.com/2014/04/gziphttp.html この辺にソースの全容が書いてますね 要求してきた側がそもそも圧縮方法をどれをサポートしているのかをAccept-CharSetに設定して 応答側はそれを見て対応した圧縮を行って送り返すと 常に圧縮するって決め打ちなら問題ないかもしれな・・・通信部分は固定っぽい気もしますし大丈夫ですかね 自分も見てました。 そちらは落ち着いてますか? 既に1ブランドはテストコードも全部作って流し終えましたし もう1ブランドも設計がひと段落したので製造開始中ですね 正直そんなに負荷じゃないです 福澤さんはプロジェクトの本稼働は始まったんです? こっちも基本的に忙しくないです。 content-lengthは圧縮されている場合、サイズ変わると思います? 変りますが、圧縮してからHTTPResponseのContentに詰め込むため、勝手に圧縮後のLengthが登録されると思います ソースはこんな感じですかね・・・? ``` using FukuSample.Content; using Newtonsoft.Json; using Newtonsoft.Json.Converters; using System; using System.Collections.Generic; using System.IO; using System.IO.Compression; using System.Linq; using System.Net; using System.Text; using System.Threading.Tasks; namespace FukuSample { class Service { public async void start(string[] prefixes) { var listener = new HttpListener(); listener.Prefixes.Add(prefixes[0]); listener.Start(); while (true) { var context = await listener.GetContextAsync(); var request = context.Request; var response = context.Response; // 接続を受け入れたら後続の処理をTaskに放り込む await Task.Run(async () => { var clientIP = request.RemoteEndPoint.Address.ToString() + ":" + request.RemoteEndPoint.Port.ToString(); using (var stream = request.InputStream) using (var reader = new StreamReader(stream)) using (var writer = new StreamWriter(response.OutputStream)) { // ヘッダ部分を全部読んでおく var requestHeaders = new List<string>(); while (true) { var line = await reader.ReadLineAsync(); //var line = reader.ReadToEnd(); if (String.IsNullOrWhiteSpace(line)) { break; } requestHeaders.Add(line); } // 返信したいJSON var json = new HogeJson() { Data1 = "Data1", Data2 = "Data2", Data3 = "Data3", Data4 = "Data4", Data5 = "Data5", Data6 = "Data6", }; // 返信したいJSONを圧縮 var data = JsonObject2ByteArray(Json2String(json)); // JSONを返信内容に詰め込み writer.Write(data); // レスポンスを返す response.StatusCode = 200; writer.Close(); response.Close(); } }); } } public static string Json2String(object json) { return JsonConvert.SerializeObject( json, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore, DefaultValueHandling = DefaultValueHandling.Ignore, Converters = { new IsoDateTimeConverter() }, }); } private static byte[] JsonObject2ByteArray(string json) { byte[] data = null; using (var memory = new MemoryStream()) { using (var gzip = new GZipStream(memory, CompressionMode.Compress)) { byte[] buffer = Encoding.UTF8.GetBytes(json); gzip.Write(buffer, 0, buffer.Length); } data = memory.ToArray(); } return data; } } } ``` ありがとうございます。 縄田君とか元気? 津田さんも 津田さんは元気に門番してますよ 縄田さんは……炎上抱えて大変そうです 「gzipヘッダーのマジックナンバーが適切ではありません」 ってどういう意味(-。-? 関さんも手伝ってあげればいいじゃん。 プロジェクトがQRですらなさそうですし。。。 これはそんなエラー出ませんでしたが、どこで出ました? ``` public static byte[] JsonObject2ByteArray(string json) { byte[] data = null; using (var memory = new MemoryStream()) { using (var gzip = new GZipStream(memory, CompressionMode.Compress)) { byte[] buffer = Encoding.UTF8.GetBytes(json); gzip.Write(buffer, 0, buffer.Length); } data = memory.ToArray(); } return data; } ``` もしもし 7/19 はいはい jsonからある要素を削除する方法を教えてください Newtonsoftは出来れば使用しない ``` { "workbench.startupEditor": "newUntitledFile", "editor.fontFamily": "Fira Code Retina", "editor.fontLigatures": true, "[csharp]": { "files.autoGuessEncoding": false, "files.encoding": "shiftjis" } } ``` から ``` { "workbench.startupEditor": "newUntitledFile", "[csharp]": { "files.autoGuessEncoding": false, "files.encoding": "shiftjis" } } ``` みたいにしたいってことですかね? はいそうです JSONで飛んでくる奴ですか? それとも内部で持ってるクラスのデータなんかをJSON化するときの話ですか? Newtonsoftはできれば使用しないというのは、他ので何を使ってますかね・・・・・・? JSONで飛んできます。 Newtonsoftを使用しないっていうのは今福澤さんにNuGetパッケージを追加する権限が無いとかそういう話ですかね 最新のパッケージを自分だけ入れると、コンパイル時にエラーとなるらしい。 大プロジェクトなので、個人で入れられないみたい あんまりやりたくないですが、案その1 正規表現で気合で引っこ抜く "editor.fontLigatures": true, を削除する場合 * 最後のカンマはあるかどうか不明 // ここで正規表現の参照 > using System.Text.RegularExpressions; // 消したい項目とその値を正規表現で設定 > var reg = new Regex("\"editor.fontLigatures\": (true|false)[,]*"); > var text = "{\"workbench.startupEditor\": \"newUntitledFile\",\"editor.fontFamily\": \"Fira Code Retina\",\"editor.fontLigatures\": true,\"[csharp]\": {\"files.autoGuessEncoding\": false,\"files.encoding\": \"shiftjis\"}}"; // 対象のJSONテキストを正規表現を使用して置換 > reg.Replace(text,"") "{\"workbench.startupEditor\": \"newUntitledFile\",\"editor.fontFamily\": \"Fira Code Retina\",\"[csharp]\": {\"files.autoGuessEncoding\": false,\"files.encoding\": \"shiftjis\"}}" で、消えますね 消したい項目に入りうる値を正規表現で書いておかないとどこまで消されてしまうか分からなくなってしまうので注意ですね 消したい項目の値に{}とか"とか'とかが入ってくるとちょっとお手上げですが…… 一応正規表現は元から入ってる機能なので使い放題ですよ 大規模プロジェクトで外部からJSONが飛んできててParserが入ってないって、プロジェクト内で飛んできてるJSONを見る気が無いとしか思えないんですが 本来右から左へ中身ノーチェックで横流ししてたような感じなんですかね・・・ ありがとうございます。 もしもし linqとかで取得できないですかね? 削除じゃなくて、必要な要素取得でもいいです。 もしもし JSONがネスト構造を持ってた時点でLINQがほぼ無理になりますが。。。 そもそもJSONの構造は事前に把握しているのですか? .Netの組み込みのライブラリではこの辺が参考になりますかね https://takachan.hatenablog.com/entry/2017/01/18/120000 http://yasuand.hatenablog.com/entry/2013/09/12/051655 おとなしく一度Parseして内部に持つしかないんじゃないですかね。。。 LINQみたいにって json.Where(j=>j.Key="Data").Value みたいにってやつです? はいできませんか? おそらく手ごろで一番近いのはDynamicJSONですね NuGetパッケージなので多分無理です https://www.ipentec.com/document/csharp-parse-json-by-using-dynamic-json どーーーしても、どーーーーしてもLINQで一行で書きたいんだ! っておっしゃるなら http://neue.cc/2010/04/29_255.html を参考にJsonReaderWriterFactoryのラッパークラスを別途作成し、 そのXElementに対してLINQ式を記述すれば 書きたいところでは1行で済むかもしれませんよ ラッパークラスがそもそもそれなりのボリュームになりそうですが。。。 ``` void somefunc(){ // なにかしらのJSON受信処理 var json = listener.Receive(); // とりあえず特定の値をJSONから取得したい var value = hoge(json, key: "some"); // それを返すかDBに保存するとかしたい return value; } ``` っていうような処理の中で、 var value = hoge(json, key: "some"); のとこを1行で書きたいっていう話ですよね? おとなしくサブクラス作ってhogeをちゃんと作ればそれでいいと思いますがいかがでしょう 1行で書くの綺麗なんですが、パッと見て何やってるのか分からないなら、 別のメソッド作っていい感じの名前つけて、そっちで分かりやすくやったほうがいい気もします 一行で書きたいです(-。- 一行で書きたいです(-。- 一行で書きたいです(-。- ソース追加箇所は1行ですよきっと クラスファイルがまるっと一つ追加されるだけです

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully